<script type="text/javascript">
$(function(){
	var pg = App.soagov.protocolEdit.ui, pp = pg.params;	

	var frm = {
			code: pg.seek('code'),
			name: pg.seek('name'),
			version: pg.seek('version'),
			path: pg.seek('path'),
			memo: pg.seek('memo'),
		};
	function getValues(){		
		if(pp.edit == null){
			var id = null;
		}else{
			id = pp.edit.id;
		}
		return {
			id:id,
			code: frm.code.val(),
			name: frm.name.val(),
			version: frm.version.val(),
			path:frm.path.val(),
			memo: frm.memo.val(),
			projectId:pp.id
		};
	}
	
	function validate(p){
		var x = App.validate, v=App.base.validation,
		msg=pg.seek('msg').html('');
		return x(v.app.inst.serverCode, p.code, msg, '协议编号') &&
			   x(v.app.inst.serverName, p.name, msg, '协议名称') &&
			   x(v.app.inst.path, p.version, msg, '协议版本') &&
			   x(v.app.inst.path, p.path, msg, '协议路径');
	}
	
	pg.find('input').blur(function(){
		var pms = getValues();
		if(!validate(pms))
			return;
	});
	
 	function setValues(o){
		frm.code.val(o.code);
		frm.name.val(o.name);
		frm.version.val(o.version);
		frm.path.val(o.path);
		frm.memo.val(o.memo);
	} 
	
	pg.seek('ok').click(function(){
		var pms = getValues();
		if(!validate(pms))
			return;
		$.post(App.soagov.ctx + '/protocol/info/save.do', pms, function(rs){
			console.log(rs);
			var ro = mac.eval(rs);
			if (ro.success) {
				pg.close();
				pg.callback();
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return false;
	});
	pg.seek('close').click(function(){
		pg.close();
	});

	if(pp.edit != null){
		setValues(pp.edit);
	}
});
</script>
<div class="left">
	<div class="form">
		<div class="item">
			<span class="label">协议编号：</span>
			<input type="text" name="code" />
			<span class="msg">*</span>
			<div class="clear"></div>
		</div>
		<div class="item">
			<span class="label">协议名称：</span>
			<input type="text" name="name"  />
			<span class="msg">*</span>
			<div class="clear"></div>
		</div>
		<div class="item">
			<span class="label">协议版本：</span>
			<div class="input">
				<input type="text" name="version"   />
				<span class="msg">*</span>
			</div>
			<div class="clear"></div>
		</div>
		<div class="item">
			<span class="label">协议路径：</span>
			<input type="text" name="path"   />
			<span class="msg">*</span>
			<div class="clear"></div>
		</div>
		<div class="item">
			<span class="label">备注：</span>
			<input type="text" name="memo"  />
			<div class="clear"></div>
		</div>
		<div class="item">
			<span class="label"></span>
			<span class="msg" name="msg"></span>
			<div class="clear"></div>
		</div>
		<div class="bottom">
			<button name="ok" class="addBtn">确定</button>
			<button name="close" class="addBtn">取消</button>
		</div>
	</div>
</div>
